﻿using BLL.DTO.UserDto;
using DAL.Service;
using Helper;
using HZY.Framework.DependencyInjection;
using Mapster;
using Model.Entity;
using Model.EntityInfo;

namespace BLL.Manager
{
    public class UserManager : IScopedSelfDependency
    {
        private readonly UserService _userService;

        public UserManager(UserService userService)
        {
            _userService = userService;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="loginDto">用户名和密码</param>
        /// <returns></returns>
        public async Task<BaseResult<UserInfoModel>> LoginReqAsync(UserLoginDto loginDto)
        {
            UserEntity userEntity = loginDto.Adapt<UserEntity>();
            var res = await _userService.LoginAsync(userEntity);
            return res;
        }
        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="userDto"></param>
        /// <returns></returns>
        public async Task<BaseResult<string>> CreateUserAsync(UserCreateDto userDto)
        {
            UserEntity userEntity = userDto.Adapt<UserEntity>();
            return await _userService.CreateUserAsync(userEntity);
        }
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="userDto"></param>
        /// <returns></returns>
        public async Task<BaseResult<string>> UpdateUserAsync(UserUpdataDto userDto)
        {
            UserEntity userEntity = userDto.Adapt<UserEntity>();
            return await _userService.UpdataUserAsync(userEntity);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="userDto"></param>
        /// <returns></returns>
        public async Task<BaseResult<string>> DelUserAsync(UserDeleteDto userDto)
        {
            UserEntity userEntity = userDto.Adapt<UserEntity>();
            return await _userService.DelUserAsync(userEntity);
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <returns></returns>
        public async Task<BaseResult<List<UserInfoModel>>> GetUserLidtAsync()
        {
            return await _userService.GetUserLidtAsync();
        }

        public async Task<BaseResult<List<RouteInfoModel>>> GetUserRoutesAsync(UserGetMyRoutesDto userDto)
        {
            return await _userService.GetUserRoutesAsync(userDto.RoleId);
        }
    }
}
